<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle"
               @onCollapse="collapseHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams2"
      :isSelectColumn="false"
      isExportExcel2
      datakey="records"
      :onRowSelectChange="selectChange"
      :onColumnsChange="columns => this.columns = columns"
    >
      <template slot="controls" slot-scope="props">
      </template>
    </FilterTable>
    <Drawer :visible.sync="visibleDrawer" :title="dialogTitle" destroyOnClose width="60vw"
            :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
    </Drawer>
  </div>
</template>

<script>
  import {getBOOrderList, postUpdateStatus} from '@/api/partsmanage/purchaseManage/purchaseSubmit';
  import {ddlxArr, mxddztArr} from '../purchaseSubmit/constant';
  import {dictionary} from '@/utils/dictMixin';
  import { getCurrentUser } from '@/api/cms-api/origin/construct/dealer';
  export default {
    name: "BOQuery",
    components: {
    },
    mixins: [dictionary],
    data() {
      return {
        topFilterList: this.createTopFilterList(),
        columns: this.createTableColumns(),
        fetchApi: getBOOrderList,
        pageType: 'query', //查询页面类型 cancelApply：BO取消申请 ，query：BO查询页面
        fetchParams: {
          xhrAbort: true
        },
        visibleDrawer: false,
        handleType: '',
        formData: {},
        dialogTitle: '配件采购提报',
        initData: {},
        rowSelectData: [],
      };
    },
    computed: {
      fetchParams2() {
        return {
          pageType: this.pageType,
          ...this.fetchParams
        }
      }
    },
    async created() {
      // this.columns.find(x => x.dataIndex === 'bjpjsx').hidden = true;
      // this.columns.find(x => x.dataIndex === 'bjpjsx').dictItems = this.createDictList('5000');
      // 获取当前登录人信息
      await getCurrentUser({}).then(response => {
        console.info(response);
        if (response.data.appId === 'beijing') {
          console.info(this.topFilterList);
          this.topFilterList.find(x => x.fieldName === 'bjpjsx').hidden = false;
          // this.columns.find(x => x.dataIndex === 'bjpjsx').hidden = false;
        }
      });
    },
    methods: {
      createTopFilterList() {
        return [
          {type: 'INPUT', label: '采购单号', fieldName: 'xsddhm', placeholder: '请输入'},
          {type: 'INPUT', label: 'SAP单号', fieldName: 'sapdh', placeholder: '请输入'},
          {type: 'SELECT', label: '订单类型', fieldName: 'xsddlx', placeholder: '请选择', itemList: ddlxArr},
          {type: 'SELECT', label: '配件属性', fieldName: 'bjpjsx', placeholder: '请选择', hidden: true, itemList: this.createDictList('5000')},
          {type: 'INPUT', label: '配件代码', fieldName: 'bjxmbh', placeholder: '请输入配件代码'},
          {type: 'INPUT', label: '配件名称', fieldName: 'bjzwmc', placeholder: '请输入配件名称'},
        ]
      },
      createTableColumns() {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 70,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          {
            title: '采购单号',
            width: 150,
            dataIndex: 'partOrder.xsddhm',
            sorter: true,
          },
          {
            title: 'SAP单号',
            dataIndex: 'partOrder.sapdh',
            sorter: true,
          },
          {
            title: 'SAP行号',
            dataIndex: 'bsddhh',
            sorter: true,
          },
          {
            title: '订单类型',
            dataIndex: 'partOrder.xsddlx',
            sorter: true,
            dictItems: ddlxArr,
          },
          {
            title: '厂家发货仓库',
            dataIndex: 'centralWarehouse.bsckmc',
            sorter: true,
          },
          {
            title: '配件代码',
            dataIndex: 'partInfo.bjxmbh',
            sorter: true,
          },
          {
            title: '配件名称',
            dataIndex: 'partInfo.bjzwmc',
            sorter: true,
          },
          {
            title: 'BO订单状态',
            dataIndex: 'xsddzt',
            sorter: true,
            dictItems: mxddztArr,
          },
          {
            title: '采购数量',
            dataIndex: 'bstxsl',
            sorter: true,
          },
          {
            title: '审批数量',
            dataIndex: 'bsspsl',
            sorter: true,
          },
          {
            title: 'BO数量',
            dataIndex: 'bsbosl',
            sorter: true,
          },
          {
            title: '取消数量',
            dataIndex: 'qxsl',
            sorter: true,
          },
          {
            title: 'B/O确认时间',
            dataIndex: 'boqrsj',
            sorter: true,
            filter: true,
          },
          {
            title: '提报时间',
            dataIndex: 'partOrder.ddtbsj',
            sorter: true,
            filter: true,
          },
          {
            title: '预计到货时间',
            dataIndex: 'yjdhsj',
            sorter: true,
            filter: true,
          },
          {
            title: '跟进结果',
            dataIndex: 'bsgjjg',
          },
          {
            title: '解决途径',
            dataIndex: 'bsjjtj',
          },
        ]
      },
      addHandle() {
        this.handleType = 'add';
        this.visibleDrawer = true
      },
      detailHandle(row, handleType) {
        this.handleType = handleType;
        this.formData = {
          id: row.id,
          data: {
            ...row,
            details: []
          }
        };
        this.visibleDrawer = true
      },
      cancleHandle(row, xsddzt) {
        this.$confirm('您确定要取消吗？取消之后您不可再次操作！', '温馨提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          const res = await postUpdateStatus({
            id: row.id,
            xsddzt
          })
          if(res.resultCode == 200) {
            this.$notify.success({title: '提示信息', message: '取消成功'});
            // 重新加载
            this.fetchParams = Object.assign({}, this.fetchParams);
          }
        }).catch(() => {
        });
      },
      closeHandler(type) {
        this.visibleDrawer = false
        if (type === 'refresh') {
          // 重新加载
          this.fetchParams = Object.assign({}, this.fetchParams);
        }
      },
      selectChange(val) {
        this.rowSelectData = val;
      },
      changeHandle(val) {
        this.fetchParams = Object.assign({}, val);
      },
      collapseHandle() {
        this.$nextTick(() => {
          this.BaseTable.EXECUTE_RESET_HEIGHT();
        });
      },
    }
  }
</script>

<style scoped>

</style>
